package com.mao.interclass;

import java.util.Arrays;
import java.util.Comparator;

public class Test2 {
    public static void main(String[] args) {
        // 完成数组排序，理解匿名内部类的用法
        // 准备一个学生类型的数组，存放6个学生对象
        Student[] students = new Student[6];
        students[0] = new Student("吴京", 36, 1.80, '男');
        students[1] = new Student("刘德华", 60, 1.76, '男');
        students[2] = new Student("周星驰", 50, 1.88, '男');
        students[3] = new Student("吴奇隆", 40, 1.70, '男');
        students[4] = new Student("吴孟达", 30, 1.68, '男');
        students[5] = new Student("周润发", 20, 1.73, '男');
        // 调用API对数组进行排序
        // public static <T> void sort(T[] a, Comparator<T> c)
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                // 按照年龄进行排序
                return o1.getAge() - o2.getAge();
            }
        });
        for (Student s : students) {
            System.out.println(s);
        }
    }
}
